﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Negocio;
using System.Data;
using System.Data.SqlClient;
using System.IO;


namespace Presentacion

{
    

    public partial class _VerConcursos : System.Web.UI.Page
    {

      
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
                gvMostrar(sender, e);
        }



        protected void gvMostrar(object sender, EventArgs e)
        {
            GridView1.DataSource = AccesoLogica.ObtenerConcurso();
            GridView1.DataBind();
        }

        protected void linkdescarga_click(object sender, EventArgs e)
        {
            DataTable dt = AccesoLogica.descargarPDF(Int32.Parse(txtID.Text));
            try
            {
                string x = dt.Rows[0][0].ToString();
                download(dt);
            }
            catch
            {
                lblstatus.Text = "Estado: No existe ese id.";
            }

        }

        private void download(DataTable dt)
        {
            Byte[] bytes = (Byte[])dt.Rows[0]["Datos"];
            Response.Buffer = true;
            Response.Charset = "";
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            Response.ContentType = dt.Rows[0]["Tipo"].ToString();
            Response.AddHeader("content-disposition", "attachment;filename=" + dt.Rows[0]["Nombre"].ToString());
            Response.BinaryWrite(bytes);
            Response.Flush();
            Response.End();
        }
}
}
